package com.xlj.function;

import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by user on 17/7/13.
 */
public class MapSortDemo {

    @Test
    public void map(){
        Map<Integer, String> random = new HashMap<Integer, String>();

        random.put(1,"z");
        random.put(6,"k");
        random.put(5,"a");
        random.put(3,"f");
        random.put(9,"c");

                random.entrySet().stream()
                        .sorted((a,b) -> b.getValue().compareTo(a.getValue()))
                .limit(3)
                .forEach(System.out::println);
                        /*.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
                                (e1, e2) -> e2, LinkedHashMap::new));*/
        //System.out.println("Sorted Map: " + Arrays.toString(sortedMap.entrySet().toArray()));
    }
}
